package Sockets;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.util.List;

/**
 *
 * @author Alejandro Figueroa
 */
public class Interfaz extends javax.swing.JFrame {

    // <editor-fold defaultstate="collapsed" desc="Variables">

    private int capacidadTanque = 0;
    private int capacidadMaxima = 50000;
    private boolean alarma = false;
   // private Interfaz server;
    private int puerto = 0;
    private String ip;
    private String url;
    private int puerto2;
    private Loggers bitacora = new Loggers();

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructores">

    public Interfaz() {
        initComponents();
        puerto = 9998;
        puerto2= 8888;
        ip = "localhost";
        url = "//" + ip + ":" + puerto + "/Tanque3";
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Codigo Generado">

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        ver = new javax.swing.JTextArea();
        entrada = new javax.swing.JButton();
        activar = new javax.swing.JButton();
        visualizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Visualizar Tanque 2");

        ver.setColumns(20);
        ver.setRows(5);
        jScrollPane1.setViewportView(ver);

        entrada.setText("Entrada Petroleo");
        entrada.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                entradaMouseClicked(evt);
            }
        });

        activar.setText("Activar Tanque");
        activar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                activarMouseClicked(evt);
            }
        });

        visualizar.setText("Visualizar Bitacora");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(activar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(visualizar, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(entrada)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(activar)
                    .addComponent(entrada)
                    .addComponent(visualizar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // </editor-fold>

    private void activarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_activarMouseClicked



      

        //desabilitamos el boton una vez que se haya activado el tanque
        this.setEnabled(false);

    }//GEN-LAST:event_activarMouseClicked

    private void entradaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_entradaMouseClicked

        lecturaXML lectura = new lecturaXML();
        List entradas = lectura.runLectura();
        XmlTanque este = null;

        if(entradas != null && entradas.size() > 0) {

            for(int i = 0 ; i < entradas.size();i++) {

                este = (XmlTanque)entradas.get(i);
		this.ver.append("Tanque: " + String.valueOf(este.getId()) + "\n");
                this.ver.append("Litros Entrantes: " + String.valueOf(este.getLitrosEntrada()) + "\n\n");
            }

	}

    }//GEN-LAST:event_entradaMouseClicked



    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interfaz().setVisible(true);
            }

        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton activar;
    private javax.swing.JButton entrada;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea ver;
    private javax.swing.JButton visualizar;
    // End of variables declaration//GEN-END:variables

}
